<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
    <head>
        <th:block th:include="include :: header('预览考试题')"/>

    </head>
    <body class="white-bg">
        <div class="wrapper wrapper-content animated fadeInRight ibox-content">

            <form class="form-horizontal m" id="form-exam-edit" th:object="${bizCourseExam}">
<!--                <div class="row">[[*{examContent}]]</div>-->
                <input name="examId" th:field="*{id}" type="hidden">

                <div class="row" th:each="exam:*{examList}">
                    <div th:text="${exam._title}">题目</div>
                    <div class="col-sm-10">
                        <div th:class="${exam.type}" th:each="sel:${exam._select}">
                            <label ><input required th:type="${exam.type}" th:name="${exam.name}" th:value="${sel.value}">[[${sel._item_title}]]</label>
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <th:block th:include="include :: footer"/>
        <script type="text/javascript">
            var prefix = ctx + "biz/exam"
            $("#form-exam-edit").validate({
                                              focusCleanup: true
                                          });

            function submitForm() {
                if ($.validate.form()) {

                    const courseDetailId = $('input[name=courseDetailId]').val()
                    if (!courseDetailId) {
                        $.modal.msgError("请选择所属课程");
                        return false
                    }
                    let data = $('#form-exam-edit').serialize();
                    debugger
                    console.log(data)

                    $.operate.save(prefix + "/edit", data);
                }
            }

            function submitHandler() {
                let data = $('#form-exam-edit').serializeObject();
                console.log('>>>>>用户答案')
                console.log(data)
                if ($.validate.form()) {
                    let data = $('#form-exam-edit').serialize();
                    $.operate.save(prefix + "/commitExam", data);
                }else{
                    console.error('试卷未填写完...')
                }
            }


            $.fn.serializeObject = function() {
                var o = {};
                var a = this.serializeArray();
                $.each(a, function () {
                    if (o[this.name] !== undefined) {
                        if (!o[this.name].push) {
                            o[this.name] = [o[this.name]];
                        }
                        o[this.name].push(this.value || '');
                    } else {
                        o[this.name] = this.value || '';
                    }
                });
                return o;
            }
        </script>


    </body>
</html>